Shader "Study/Chapter4/StencilColor"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)

	 	
		_StencilId("StencilID", int) = 0
        [Enum(UnityEngine.Rendering.CompareFunction)]_StencilComp ("Stencil Comparison", int) = 8  
        // 通过后的操作
        [Enum(UnityEngine.Rendering.StencilOp)]_StencilPass ("_Stencil Pass", int) = 0
		[Enum(UnityEngine.Rendering.StencilOp)]_StencilFail ("_Stencil Fail", int) = 0
		[Enum(UnityEngine.Rendering.StencilOp)]_StencilZFail ("_Stencil ZFail", int) = 0
        // _StencilWriteMask ("Stencil Write Mask", int) = 255
        // _StencilReadMask ("Stencil Read Mask", int) = 255
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        // 模板测试相关
        Stencil
        { 
            Ref [_StencilId]              // 关键字 当前写入到模板缓存中的值
            Comp [_StencilComp]         // 对比
            Pass [_StencilPass]           // 对比通过之后的处理方式  keep 保持不变  因为做的是遮罩效果，则当有满足缓存区间内的内容保持渲染
            Fail [_StencilPass]
			ZFail [_StencilPass]
			// ReadMask [_StencilReadMask]
            // WriteMask [_StencilWriteMask]
        }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

            float4 _Color;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                return _Color;
            }
            ENDCG
        }
    }
}
